package com.tfy.liquor.dao;

import com.tfy.liquor.bean.CategoryInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Mapper
@Service
public interface CategoryInfoDao {
    // 添加类别信息
    @Insert("insert into category_info values(null, ${parentId}, '${categoryName}', 0)")
    int addCategoryInfo(CategoryInfo categoryInfo);

    // 获取类别信息
    @Select("select * from category_info where status=0 order by categoryId desc")
    ArrayList<CategoryInfo> getCategoryInfo();

    // 获取全部类别信息
//    @Select("select * from category_info order by categoryId desc")
    @Select({"<script>" +
            "select * from category_info " +
            "where 1=1" +
            "<if test='categoryName != null'>and categoryName like '%${categoryName}%'</if>" +
            "order by categoryId desc" +
            "</script>"})
    ArrayList<CategoryInfo> getAllCategoryInfo(String categoryName);

    // 修改类别信息
    @Update("update category_info set categoryName='${categoryName}' where categoryId=${categoryId}")
    int editCategoryInfo(CategoryInfo categoryInfo);

    // 停用此类别
    @Update("update category_info set status=1 where categoryId=${categoryId}")
    int stopCategoryInfo(CategoryInfo categoryInfo);

    // 启用此类别
    @Update("update category_info set status=0 where categoryId=${categoryId}")
    int enableCategoryInfo(CategoryInfo categoryInfo);
}
